home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Using the %c control in SCANF
- Date: 9 Apr 1996 07:40:13 GMT
- Organization: systems hk
- Message-ID: <4kd48t$k1h@nadine.teleport.com>
- References: <4k9j02$fl9@arl-news-svc-5.compuserve.com>
- NNTP-Posting-Host: ip-pdx07-07.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- Philippe Verdy <100105.3120@compuserve.com> wrote:
- >> Can anyone please give me some examples of using the %c control in the
- >> scanf function.
- [snip]
- >> Can anyone help me use the %c control properly? If not, do you know of a
- >> better way of accomplishing this, perhaps with iostream.h functions instead?
- --------------
- >Your error is normal: with %s you read a line into textLine,
- >then with %c you read a character which should be stored in
- >the next variable. But you did not specify that variable as
- >an argument.
- >char textLine[MAXBUFFERSIZE], x;
- >scanf("%s%c", textLine, x);
- >Note that you must enter two lines prior to having results:
- >%s reads all until the end-of line. then %c returns the first
- >character of the next line entered.
- >
- [snip]
- --------------
- A couple of problems with the response:
-
- scanf requires pointers as arguments, therefore it should read:
-
- scanf( "%s %c",textLine,&x );
-
- Also, if there is whitespace after an contiguous stream of characters
- in the record, then I assume that '&x' will pick up the next
- character in the _same_ record.
-
- Yours, Geoff Houck
-
-